//
//  HBSearchResultFooterView.m
//  HeartBeat
//
//  Created by karong on 2023/8/25.
//

#import "HBSearchResultFooterView.h"
#import "HBDiscoverItemNovel2Cell.h"

@interface HBSearchResultFooterView ()
@property (weak, nonatomic) IBOutlet UICollectionView *listView;
@property (nonatomic, strong) NSMutableArray * dataArray;
@end

@implementation HBSearchResultFooterView

- (void)awakeFromNib {
    [super awakeFromNib];
    UINib * nib = [UINib nibWithNibName:@"HBDiscoverItemNovel2Cell" bundle:nil];
    [self.listView registerNib:nib forCellWithReuseIdentifier:@"HBDiscoverItemNovel2Cell"];
}

- (void)setDataWithObject:(id)object {
    self.dataArray = object;
    [self.listView reloadData];
}
#pragma mark UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HBDiscoverItemNovel2Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HBDiscoverItemNovel2Cell" forIndexPath:indexPath];
    [cell setDataWithObject:self.dataArray[indexPath.row] index:indexPath.row];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size = CGSizeZero;
    size.width = collectionView.width;
    size.height = 70;
    return size;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(searchResultFooterViewActionWithObjct:)]) {
        [self.delegate searchResultFooterViewActionWithObjct:self.dataArray[indexPath.row]];
    }
}
@end
